package classes;

import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ListaAlimento extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        System.out.println("TESTE1");
        processRequest(request, response);  
    }
    
    private static ListaAlimento instance = null;
    
    public static ListaAlimento getInstance() {
        if (instance == null) {
            instance = new ListaAlimento();
        }
        return instance;
    }

    public ArrayList<Alimento> list = new ArrayList();

    public String getValores(Long cd_alimento) {
        for (Alimento meal : list) {
            if (meal.getCd_alimento().equals(cd_alimento)) {
                return meal.getQt_alimento() + "g" + ", " + meal.getDs_alimento_equivalencia();
            }
        }
        return "";
    }

    void processRequest(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("TESTE");
        getValores(Long.parseLong(request.getParameter("cd_alimento")));
    }

}
